home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 2000
/
MacHack 2000.toast
/
pc
/
The Hacks
/
Softshoe
/
Lisa's Mac Parts
/
Views
/
Tiled Views
/
PaneColumn.cp
next >
Wrap
Text File
|
2000-06-23
|
4KB
|
150 lines
// PaneColumn.cp
#ifndef PaneColumn_h
#include "PaneColumn.h"
#endif
#ifndef MinMax_h
#include "MinMax.h"
#endif
#ifndef Overflow_h
#include "Overflow.h"
#endif
#ifndef TiledPane_h
#include "TiledPane.h"
#endif
void PaneColumn::PaneSizeChanged()
{
if ( !PaneSizeKnown() )
return;
Assert( !Panes().IsEmpty() );
int32 oldHeight = (*Panes().Last())->Bounds().bottom;
for ( PaneLoop pane( Panes() ); pane.Unfinished(); pane++ )
pane->proposedSize = 0;
int32 remainder = Asint32( PaneSize().v );
for ( PaneLoop pane( Panes() ); remainder > 0 && pane.Unfinished(); pane++ )
{
uint32 minimum = Min( remainder, pane->Sizer().MinimumHeight() );
pane->proposedSize = minimum;
remainder -= minimum;
}
Assert( TotalProposedSize() + remainder == Asint32( PaneSize().v ) );
for ( PaneLoop pane( Panes() ); remainder > 0 && pane.Unfinished(); pane++ )
{
int32 best = pane->Sizer().BestHeight( Range32( pane->proposedSize,
pane->proposedSize + remainder ) );
int32 increase = best - pane->proposedSize;
remainder -= increase;
pane->proposedSize += increase;
}
Assert( TotalProposedSize() + remainder == Asint32( PaneSize().v ) );
for ( PaneLoop pane( *Panes().Last() ); remainder > 0 && pane.Unfinished(); pane-- )
{
int32 maximum = Min( pane->proposedSize + remainder,
pane->Sizer().MaximumHeight() );
int32 increase = maximum - pane->proposedSize;
remainder -= increase;
pane->proposedSize += increase;
}
Assert( TotalProposedSize() + remainder == Asint32( PaneSize().v ) );
if ( remainder > 0 )
(*Panes().Last())->proposedSize += remainder;
Assert( TotalProposedSize() == Asint32( PaneSize().v ) );
uint32 position = 0;
for ( PaneLoop pane( Panes() ); pane.Unfinished(); pane++ )
{
pane->proposedBounds = Rectangle32( 0, position,
PaneSize().h, position + pane->proposedSize );
position += pane->proposedSize;
}
if ( oldHeight <= PaneSize().v )
ShufflePanesForward();
else
ShufflePanesBackward();
}
int32 PaneColumn::MinimumHeight() const
{
return TotalOf( &SuggestsPaneSize::MinimumHeight );
}
int32 PaneColumn::MinimumWidth() const
{
return MaximumOf( &SuggestsPaneSize::MinimumWidth );
}
int32 PaneColumn::MaximumHeight() const
{
return TotalOf( &SuggestsPaneSize::MaximumHeight );
}
int32 PaneColumn::MaximumWidth() const
{
return MinimumOf( &SuggestsPaneSize::MaximumWidth );
}
int32 PaneColumn::ReasonableHeight() const
{
return TotalOf( &SuggestsPaneSize::ReasonableHeight );
}
int32 PaneColumn::ReasonableWidth() const
{
return MaximumOf( &SuggestsPaneSize::ReasonableWidth );
}
int32 PaneColumn::BestHeight( Range32 bounds ) const
{
int32 remainder = bounds.End();
for ( PaneLoop pane( Panes() ); remainder > 0 && pane.Unfinished(); pane++ )
{
uint32 minimum = Min( remainder, pane->Sizer().MinimumHeight() );
pane->proposedSize = minimum;
remainder -= minimum;
}
for ( PaneLoop pane( Panes() ); remainder > 0 && pane.Unfinished(); pane++ )
{
int32 best = pane->Sizer().BestHeight( Range32( pane->proposedSize,
pane->proposedSize + remainder ) );
remainder -= best - pane->proposedSize;
pane->proposedSize = best;
}
return bounds.WeaklyRestrict( bounds.End() - remainder );
}
int32 PaneColumn::BestWidth( Range32 bounds ) const
{
bounds.SetStart( bounds.WeaklyRestrict( MinimumWidth() ) );
bounds.SetEnd( bounds.WeaklyRestrict( MaximumWidth() ) );
int32 best = 0;
for ( PaneLoop pane( Panes() ); pane.Unfinished(); pane++ )
best = Max( best, pane->Sizer().BestWidth( bounds ) );
return best;
}